package cn.edu.zknu.mita.controller;

import cn.edu.zknu.mita.model.FindMsg;
import cn.edu.zknu.mita.service.IFindMsgService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class MessageController {

    @Autowired
    private IFindMsgService findMsgService;

    @RequestMapping("/findMessage")
    public String findMessage(@RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "30") Integer pageSize, Integer type, Model model){
        PageInfo<FindMsg> info = findMsgService.listFindMsg(pageNum, pageSize, type);
        model.addAttribute("info",info);
        model.addAttribute("type",type);
        return "FindMessage";
    }

    @RequestMapping("/search")
    public String searchMessage(@RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "30") Integer pageSize, @RequestParam(defaultValue = "") String key, Model model){
        PageInfo<FindMsg> info = findMsgService.searchMsg(pageNum, pageSize, key);
        model.addAttribute("info",info);
        model.addAttribute("keyword",key);
        return "SearchMessage";
    }
}
